package com.lmmob.autotest.uitest.controls;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class MessageBox extends Window {

    private Button btnOk;
    private Button btnYes;

    public MessageBox(String title, WebDriver webDriver) {
        super(title, webDriver);
        btnOk = new Button("确定", webDriver);
        btnYes = new Button("是", webDriver);
        this.addChild(btnOk);
        this.addChild(btnYes);
    }

    public void accept() {
        btnOk.click();
    }

    public void yes() {
        btnYes.click();
    }

    public String getMessage() {
        String bodyId = (String) runScript("return " + this.getQuery() + ".body.id");
        WebElement winElement = findElement(By.id(bodyId));
        return winElement.findElement(By.tagName("span")).getText();
    }
}
